import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  ParseIntPipe, Put,
} from '@nestjs/common';
import { GoodsService } from './goods.service';
import { CreateGoodsDto } from './dto/create-goods.dto';
import { GoodsEntity } from './goods.entity';

@Controller('goods')
export class GoodsController {
  constructor(private readonly goodsService: GoodsService) {}


  @Post()
  create(@Body() createGoodsDto: CreateGoodsDto): Promise<GoodsEntity> {
    return this.goodsService.create(createGoodsDto);
  }

  @Get()
  findAll(): Promise<GoodsEntity[]> {
    return this.goodsService.findAll();
  }

  @Get(':id')
  findOne(@Param('id', ParseIntPipe) id: number): Promise<GoodsEntity> {
    return this.goodsService.findOne(id);
  }

  @Get('marketList/:businessId')
  market(@Param('businessId', ParseIntPipe) businessId: number): Promise<GoodsEntity[]> {
    return this.goodsService.marketList(businessId);
  }

  //我上架的物品
  @Post('mySellGoods')
  mySellGoods(@Body() createGoodsDto: CreateGoodsDto,): Promise<GoodsEntity[]> {
    //获取本机rul
    return this.goodsService.sellGoods(createGoodsDto);
  }
  @Delete(':id')
  remove(@Param('id') id: string): Promise<void> {
    return this.goodsService.remove(id);
  }

  @Put(':id')
  update(@Param('id', ParseIntPipe) id: number, @Body() createGoodsDto: CreateGoodsDto): Promise<GoodsEntity> {
    return this.goodsService.update(id, createGoodsDto);
  }

  @Get('transaction/:userId')
  async getTransactionList(@Param('userId', ParseIntPipe) userId: number): Promise<GoodsEntity[]> {
    return this.goodsService.findGoodsByCondition(userId);
  }
}